$(function(){
   'use strict'
	var loginForm = $('#login_form'),
		inputEmail =$('#input_email'),
		inputPassword = $('#input_password'),
		loginButton = $('#login-button'),
		inputEmailError =$('#input_email_error'),
		inputPasswordError = $('#input_password_error')




	inputEmail.on('keyup',function(){

		clearError($(this))
	})


	inputPassword.on('keyup',function(){

		clearError($(this))
	})



	loginButton.on('click',function(){
		//email或password值是否为空检查
		if(inputEmail.val() == undefined || inputEmail.val() == "" || inputPassword.val() == undefined || inputPassword.val() ==""){

			if(inputEmail.val() == undefined || inputEmail.val() == ""){

			isNull(inputEmail,'邮箱不能为空')


		}

			if(inputPassword.val() == undefined || inputPassword.val() ==""){

			isNull(inputPassword,'密码不能为空')

		}

			return 

		}


		$.ajax({

			type:'post',
			url:'/signin/access',
			data:{
				user:{
					email:inputEmail.val(),
					password:inputPassword.val()
				}
			},

			success:function(data){
				//-1表示邮箱未注册
				if(data.status ==1 && data.email == false){

					isNull(inputEmail,'该邮箱尚未注册')
				}else if(data.status == 1 && data.password == false){
					isNull(inputPassword,'密码不正确')
				}else if(data.status == 1 && data.email == true && data.password == true){

					window.location.href = '/index'

				}else{

					//TODO,错误情况暂不处理
				}
			}
		})



	})


})